Skip to main content

Overview

gdal2xyz_geocentricSpace.py translates GDAL-supported rasters (specifically elevation DEMs) into geocentric (body-fixed) XYZ ASCII tables, ideal for planetary surface analysis and 3D modeling.

Purpose

Convert planetary elevation data into geocentric coordinate systems, transforming latitude/longitude/elevation values into 3D Cartesian coordinates (X, Y, Z) in a body-fixed reference frame. Original Author: Frank Warmerdam (original gdal2xyz)
Updates: Trent Hare, USGS (geocentric conversion functionality)

Installation Requirements

Command Syntax

Parameters

string
required
Input GDAL-supported raster file (DEM with elevation in meters)
string
Output CSV file. If omitted, writes to stdout
integer
default:"1"
Sampling factor (e.g., -skip 2 outputs every other pixel)
float
default:"1737400.0"
Body radius in meters. Defaults to Moon radius (1737400.0 m)
integer
Band number containing variable radius values
integer
Band number containing latitude values (overrides GDAL calculation)
integer
Band number containing longitude values (overrides GDAL calculation)
integer
default:"1"
Elevation band number (band 1 by default)
string
Specify subwindow: xoff yoff width height (in pixels)
flag
Add CSV header row with field names
flag
Output Lat/Lon/Elevation instead of geocentric XYZ

Usage Examples

Basic Geocentric Export (Moon)

Export with default Moon radius to stdout:
Output format:

Export to File with Header

Custom Body Radius (Mars)

Use Mars mean radius (3389500 m):

Using Lat/Lon from Bands

When latitude and longitude are stored in separate bands:

Variable Radius from Band

For data with variable radius (e.g., asteroid shape models):

Static Radius with Lat/Lon Bands

Output Lat/Lon/Elevation Only

Output format:

Subsample and Clip

Process every 10th pixel from a subwindow:

Geocentric Coordinate Transformation

Mathematical Formula

The script converts from spherical to Cartesian coordinates using (see gdal2xyz_geocentricSpace.py:268-277): Standard formula (with elevation):
Variable radius formula (radius in band):
The transformation assumes a simple sphere model. For ellipsoidal bodies, the formulas would need modification.

Coordinate System

  • X-axis: Points toward 0° longitude (prime meridian)
  • Y-axis: Points toward 90°E longitude
  • Z-axis: Points toward North pole
  • Origin: Body center of mass

Input Projection Handling

The script supports any GDAL meter-based projection as input (see gdal2xyz_geocentricSpace.py:172-179):
Automatic Detection:
  • If input is already Lat/Lon (values ≤ 360°), uses coordinates directly
  • For projected coordinates (meters), transforms to Lat/Lon first
  • Elevation values must be in meters

Planetary Body Radii

Common Body Radii (meters)

These are mean radii. For accurate work with ellipsoidal bodies, use the equatorial radius or consider the ellipsoidal nature of the body.

Output Formats

Geocentric XYZ (default)

Format: %.3f,%.3f,%.3f (3 decimal places)

Lat/Lon/Elevation (-printLatLon)

Format: %.6f,%.6f,%.3f (6 decimals for coordinates, 3 for elevation)

Advanced Use Cases

Case 1: Multi-band Lat/Lon/Elevation

For files where bands contain:
  • Band 1: Elevation (m)
  • Band 2: Latitude (decimal degrees)
  • Band 3: Longitude (decimal degrees)

Case 2: Asteroid Shape Model

For shape models with radius values instead of elevation:

Case 3: Large Dataset Subsampling

Process every 100th pixel for visualization:

Performance Considerations

Memory Efficient: The script processes data line-by-line, making it suitable for very large rasters.

Processing Speed

For a 10000x10000 pixel DEM:
  • With -skip 1: ~2-3 minutes
  • With -skip 10: ~10-15 seconds
  • With -skip 100: ~1-2 seconds

Output File Size

Each point generates ~30-40 bytes of CSV data:
  • 100x100 grid (10,000 points): ~400 KB
  • 1000x1000 grid (1M points): ~40 MB
  • 10000x10000 grid (100M points): ~4 GB

Data Validation

Check for Valid Elevation Values

The script filters out invalid data (see gdal2xyz_geocentricSpace.py:263):
Values with absolute magnitude ≥ 1×10¹² are considered invalid and skipped.

Integration with Other Tools

Import into 3D Software

ParaView:
CloudCompare:

GIS Analysis

Import XYZ coordinates back into GIS:

Source Code Reference

  • gdal2xyz_geocentricSpace.py:55-61 - Usage and parameter documentation
  • gdal2xyz_geocentricSpace.py:172-179 - Coordinate transformation setup
  • gdal2xyz_geocentricSpace.py:234-279 - Main processing loop and geocentric calculation
  • gdal2xyz_geocentricSpace.py:268-277 - Geocentric coordinate formulas

Limitations

  • Assumes simple sphere model (not ellipsoidal)
  • Elevation values must be in meters
  • No support for 3D ellipsoidal transformations
  • Output precision fixed at 3 decimal places for XYZ

Troubleshooting

Common Issues

Issue: Output values seem incorrect
  • Solution: Verify input elevation units are in meters
  • Solution: Check body radius is correct for your target
Issue: “Only one Lat or one Lon Band sent” error
  • Solution: When using -latBand, you must also specify -lonBand (and vice versa)
Issue: Large output file size
  • Solution: Use -skip parameter to subsample data
  • Solution: Use -srcwin to process only region of interest

See Also